package com.alivc.testmediaplayer.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

import com.alivc.testmediaplayer.R;
import com.alivc.testmediaplayer.utils.CleanLeakUtils;

public class DemoUrlActivity extends AppCompatActivity {

    private EditText mUrlEdit;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_demo_vod);

        mUrlEdit = (EditText) findViewById(R.id.url);

        findViewById(R.id.start_play).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startNoSkinActivity();
            }
        });


        String type = getIntent().getStringExtra("type");
        if(type.equals("vod")) {
            String url = "http://ytlive.oss-cn-shanghai.aliyuncs.com/record/ytlive/live_11115/2017-10-15-14:59:44_2017-10-15-16:28:18.m3u8";
            mUrlEdit.setText(url);
        }else if(type.equals("live"))
        {
            String url = "rtmp://live.hkstv.hk.lxdns.com/live/hks";
            mUrlEdit.setText(url);
        }
    }

    private void startNoSkinActivity() {

        String mUrl = mUrlEdit.getText().toString();

        if (TextUtils.isEmpty(mUrl)) {
            Toast.makeText(getApplicationContext(), R.string.url_is_empty, Toast.LENGTH_LONG).show();
            return;
        }


        Intent intent = new Intent();
        //pass the url and type to intent
        intent.putExtra("url", mUrl);
        String type = getIntent().getStringExtra("type");
        if(type.equals("vod")) {
            intent.setClass(this, VodModeActivity.class);
        }else if(type.equals("live")){
            intent.setClass(this, LiveModeActivity.class);
        }

        startActivity(intent);
    }

    @Override
    protected void onDestroy() {
        CleanLeakUtils.fixInputMethodManagerLeak(this);
        super.onDestroy();
    }
}

